using System;
using System.Collections.Generic;
using System.Linq;

namespace AltNetSundsvall.Bowling
{
    public class BowlingGame
    {
        private List<Frame> frames = new List<Frame>();


        public BowlingGame()
        {
            frames.Add(new Frame());
        }

        //public int Score
        //{
        //    get
        //    {
        //        int score = 0;
        //        foreach( Frame f in frames)
        //        {
        //            score += f.Score();
        //        }
        //        return score;
        //    }
        //}

    

        //public void Roll(int pins)
        //{
        //    if (frames.Last().IsDone())
        //    {
        //        var frame = new Frame();
        //        frames.Last().NextFrame = frame;
        //        frames.Add(frame);
        //    }
            
        //    frames.Last().Roll(pins);
        //}


        public int Score
        {
            get
            {
                int score = 0;
                int numRolls = rolls.Count;
                bool newFrame = true;
                for (int i = 0; i < numRolls; i++)
                {
                    int currentRoll = rolls[i];
                    if(currentRoll == 10 )
                    {
                        if(i + 2 <= numRolls)
                        {
                            score += currentRoll + rolls[i + 1] + rolls[i + 2];
                        }
                    }
                    else
                    {
                        if(!newFrame)
                        {
                            score += currentRoll;
                        }
                    }

                }
                return score;

            }
        }


        private IList<int> rolls = new List<int>();

        private int score;
        public void Roll(int pins)
        {
            rolls.Add(pins);

         

        }
    }
}